package com.hiultra.archive.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.archive.domain.ArchiveCabinet;
import com.hiultra.archive.service.IArchiveCabinetService;
import com.hiultra.common.utils.poi.ExcelUtil;
import com.hiultra.common.core.page.TableDataInfo;

/**
 * 柜Controller
 *
 * @author paidaxing
 * @date 2024-07-25
 */
@RestController
@RequestMapping("/archive/ArchiveCabinet")
public class ArchiveCabinetController extends BaseController
{

    @Value("${roomNo}")
    private String roomNo;
    @Autowired
    private IArchiveCabinetService archiveCabinetService;

    /**
     * 查询柜列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveCabinet:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArchiveCabinet archiveCabinet) throws JsonProcessingException {
        startPage();
        List<ArchiveCabinet> list = archiveCabinetService.selectArchiveCabinetList(archiveCabinet);
        return getDataTable(list);
    }

    /**
     * 查询柜列表
     */
    @GetMapping("/listAll")
    public TableDataInfo listAll(ArchiveCabinet archiveCabinet) {
        List<ArchiveCabinet> list = archiveCabinetService.selectArchiveCabinetList(archiveCabinet);
        return getDataTable(list);
    }

    /**
     * 导出柜列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveCabinet:export')")
    @Log(title = "柜", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveCabinet archiveCabinet)
    {
        List<ArchiveCabinet> list = archiveCabinetService.selectArchiveCabinetList(archiveCabinet);
        ExcelUtil<ArchiveCabinet> util = new ExcelUtil<ArchiveCabinet>(ArchiveCabinet.class);
        util.exportExcel(response, list, "柜数据");
    }

    /**
     * 获取柜详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveCabinet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(archiveCabinetService.selectArchiveCabinetById(id));
    }

    /**
     * 新增柜
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveCabinet:add')")
    @Log(title = "柜", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveCabinet archiveCabinet)
    {
        return toAjax(archiveCabinetService.insertArchiveCabinet(archiveCabinet));
    }

    /**
     * 修改柜
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveCabinet:edit')")
    @Log(title = "柜", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveCabinet archiveCabinet)
    {
        return toAjax(archiveCabinetService.updateArchiveCabinet(archiveCabinet));
    }

    /**
     * 删除柜
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveCabinet:remove')")
    @Log(title = "柜", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(archiveCabinetService.deleteArchiveCabinetByIds(ids));
    }

    @Value("${urlIp}")
    private String urlIp;
    @GetMapping("/getServerIp")
    public AjaxResult getServerIp() {
        return AjaxResult.success(urlIp);
    }
}
